package com.itheima.app.controller.pmsController;


import com.itheima.app.manager.pmsManager.PmsProductManager;
import com.itheima.commons.R;
import com.itheima.dto.pms.PmsProductDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
public class PmsProductController {

    @Autowired
    PmsProductManager pmsProductManager;

    //创建商品
    @PostMapping("/product/create")
    public R saveProduct(@RequestBody PmsProductDto productDto) {
        return pmsProductManager.saveProduct(productDto);
    }


    //查询商品
    @GetMapping("/product/list")
    public R productList(Integer brandId, String keyword, Integer pageNum, Integer pageSize,
                         Integer productCategoryId, String productSn, Integer publishStatus,
                         Integer verifyStatus) {

        return pmsProductManager.getByIdProduct(brandId, keyword, pageNum, pageSize, productCategoryId, productSn, publishStatus, verifyStatus);
    }

    //根据商品名称或货号模糊查询
    @GetMapping("/product/simpleList")
    public R simpleList(Integer keyword){
        return pmsProductManager.simpleList(keyword);
    }

    //批量修改删除状态
    @PostMapping("/product/update/deleteStatus")
    public R updateDeleteStatus(Integer deleteStatus,Integer [] ids ){

        return pmsProductManager.updateDeleteStatus(deleteStatus,ids);
    }


    //批量上下架商品
    @PostMapping("/product/update/publishStatus")
    public R updatePublishStatus(Integer publishStatus, Integer[] ids) {

        return pmsProductManager.publishStatus(publishStatus, ids);
    }

    //批量设为新品
    @PostMapping("/product/update/newStatus")
    public R newStatus(Integer newStatus, Integer[] ids) {
        return pmsProductManager.newStatus(newStatus, ids);
    }

    //批量推荐商品
    @PostMapping("/product/update/recommendStatus")
    public R recommendStatus(Integer recommendStatus, Integer[] ids) {

        return pmsProductManager.recommendStatus(recommendStatus, ids);
    }


    //更新商品
    @PostMapping("/product/update/{id}")
    public R updateById(@PathVariable Long id,@RequestBody PmsProductDto productDto){
        return pmsProductManager.updateByid(id,productDto);
    }

    //根据商品id获取商品编辑信息
    @GetMapping("/product/updateInfo/{id}")
    public R updateInfoById(@PathVariable Long id){
        return pmsProductManager.updateInfoById(id);
    }
}
